home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvhc11a.zip / TVHC.PAS < prev    next >
Pascal/Delphi Source File  |  1993-12-26  |  35KB  |  1,177 lines

  1. (***************************************************************************
  2.   TVHC 1.1a
  3.   Improved TVHC, help compiler for Turbo Vision
  4.   PJB December 26, 1993, Internet mail to d91-pbr@nada.kth.se
  5.   Free patches, use at your own risk. All warranties void.
  6.   If even more modified, please state so if you pass this around.
  7.  
  8.   BUGS fixed:
  9.     Reports the .TXT file name in error messages ("fix file name")
  10.     The next file name to be opened or created is kept in a global
  11.     variable, so the error method can find it ("fix file error")
  12.  
  13.   Improvements:
  14.     Reports the actual line numbers of all lines containing unresolved
  15.     help references ("fix unresolved msg") and both actual line numbers
  16.     for redefined help topics ("fix redefinition msg")
  17.  
  18.   The documentation lacks to mention that a line that begins with a
  19.   semi-colon is skipped.
  20.  
  21.   This is a minimally modified version manually created from Borland's
  22.   TVHC using FC output comparing TVHCHack to TVHC.
  23.  
  24. ***************************************************************************)
  25.  
  26. {************************************************}
  27. {                                                }
  28. {   Turbo Vision Demo                            }
  29. {   Copyright (c) 1992 by Borland International  }
  30. {                                                }
  31. {************************************************}
  32.  
  33. {===== TVHC version 1.1 ================================================}
  34. {  Turbo Vision help file compiler documentation.                       }
  35. {=======================================================================}
  36. {                                                                       }
  37. {    Refer to DEMOHELP.TXT for an example of a help source file.        }
  38. {                                                                       }
  39. {    This program takes a help script and produces a help file (.HLP)   }
  40. {    and a help context file (.PAS).  The format for the help file is   }
  41. {    very simple.  Each context is given a symbolic name (i.e FileOpen) }
  42. {    which is then put in the context file (i.e. hcFileOpen).  The text }
  43. {    following the topic line is put into the help file.  Since the     }
  44. {    help file can be resized, some of the text will need to be wrapped }
  45. {    to fit into the window.  If a line of text is flush left with      }
  46. {    no preceeding white space, the line will be wrapped.  All adjacent }
  47. {    wrappable lines are wrapped as a paragraph.  If a line begins with }
  48. {    a space it will not be wrapped. For example, the following is a    }
  49. {    help topic for a File|Open menu item.                              }
  50. {                                                                       }
  51. {       |.topic FileOpen                                                }
  52. {       |  File|Open                                                    }
  53. {       |  ---------                                                    }
  54. {       |This menu item will bring up a dialog...                       }
  55. {                                                                       }
  56. {    The "File|Open" will not be wrapped with the "----" line since     }
  57. {    they both begin with a space, but the "This menu..." line will     }
  58. {    be wrapped.                                                        }
  59. {      The syntax for a ".topic" line is:                               }
  60. {                                                                       }
  61. {        .topic symbol[=number][, symbol[=number][...]]                 }
  62. {                                                                       }
  63. {    Note a topic can have multiple symbols that define it so that one  }
  64. {    topic can be used by multiple contexts.  The number is optional    }
  65. {    and will be the value of the hcXXX context in the context file     }
  66. {    Once a number is assigned all following topic symbols will be      }
  67. {    assigned numbers in sequence.  For example,                        }
  68. {                                                                       }
  69. {       .topic FileOpen=3, OpenFile, FFileOpen                          }
  70. {                                                                       }
  71. {    will produce the follwing help context number definitions,         }
  72. {                                                                       }
  73. {        hcFileOpen  = 3;                                               }
  74. {        hcOpenFile  = 4;                                               }
  75. {        hcFFileOpen = 5;                                               }
  76. {                                                                       }
  77. {    Cross references can be imbedded in the text of a help topic which }
  78. {    allows the user to quickly access related topics.  The format for  }
  79. {    a cross reference is as follows,                                   }
  80. {                                                                       }
  81. (*        {text[:alias]}                                               *)
  82. {                                                                       }
  83. {    The text in the brackets is highlighted by the help viewer.  This  }
  84. {    text can be selected by the user and will take the user to the     }
  85. {    topic by the name of the text.  Sometimes the text will not be     }
  86. {    the same as a topic symbol.  In this case you can use the optional }
  87. {    alias syntax.  The symbol you wish to use is placed after the text }
  88. {    after a ':'. The following is a paragraph of text using cross      }
  89. {    references,                                                        }
  90. {                                                                       }
  91. (*      |The {file open dialog:FileOpen} allows you specify which      *)
  92. {       |file you wish to view.  If it also allow you to navigate       }
  93. {       |directories.  To change to a given directory use the           }
  94. (*      |{change directory dialog:ChDir}.                              *)
  95. {                                                                       }
  96. {    The user can tab or use the mouse to select more information about }
  97. {    the "file open dialog" or the "change directory dialog". The help  }
  98. {    compiler handles forward references so a topic need not be defined }
  99. {    before it is referenced.  If a topic is referenced but not         }
  100. {    defined, the compiler will give a warning but will still create a  }
  101. {    useable help file.  If the undefined reference is used, a message  }
  102. {    ("No help available...") will appear in the help window.           }
  103. {=======================================================================}
  104.  
  105. program TVHC;
  106.  
  107. {$S-}
  108.  
  109. {$M 8192,8192,655360}
  110.  
  111. uses Drivers, Objects, Dos, Strings, HelpFile;
  112.  
  113. { If you get a FILE NOT FOUND error when compiling this program
  114.   from a DOS IDE, change to the \BP\EXAMPLES\DOS\TVDEMO directory
  115.   (use File|Change dir).
  116.  
  117.   This will enable the compiler to find all of the units used by
  118.   this program.
  119. }
  120.  
  121. {======================= File Management ===============================}
  122.  
  123. procedure Error(Text: String); forward;
  124.  
  125. type
  126.   PProtectedStream = ^TProtectedStream;
  127.   TProtectedStream = object(TBufStream)
  128.     FileName: FNameStr;
  129.     Mode: Word;
  130.     constructor Init(AFileName: FNameStr; AMode, Size: Word);
  131.     destructor Done; virtual;
  132.     procedure Error(Code, Info: Integer); virtual;
  133.   end;
  134.  
  135. var
  136.   TextStrm,
  137.   SymbStrm: TProtectedStream;
  138.   ErrorFileName : String;                       { fix file error }
  139.  
  140. const
  141.   HelpStrm: PProtectedStream = nil;
  142.  
  143. constructor TProtectedStream.Init(AFileName: FNameStr; AMode, Size: Word);
  144. begin
  145.   ErrorFileName := AFileName;                   { fix file error }
  146.   inherited Init(AFileName, AMode, Size);
  147.   FileName := AFileName;
  148.   Mode := AMode;
  149. end;
  150.  
  151. destructor TProtectedStream.Done;
  152. var
  153.   F: File;
  154. begin
  155.   inherited Done;
  156.   if (Mode = stCreate) and ((Status <> stOk) or (ExitCode <> 0)) then
  157.   begin
  158.     Assign(F, FileName);
  159.     Erase(F);
  160.   end;
  161. end;
  162.  
  163. procedure TProtectedStream.Error(Code, Info: Integer);
  164. begin
  165.   case Code of
  166.     stError:
  167.